﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/assets/module/admin.css?v=318">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .layui-form-item {
            margin-bottom: 10px;
        }

        .form1-foot .layui-form-label, #form-preview .layui-form-label, #form4 .layui-form-label {
            width: 120px;
        }

        .form1-foot .layui-input-block, #form4 .layui-input-block {
            margin-left: 150px;
        }

        #form-preview .layui-input-block {
            margin-left: 180px;
        }

        .floot-btn {
            position: fixed;
            bottom: 0;
            right: 0;
            width: 100%;
            background: white;
            padding-top: 10px;
            padding-right: 50px;
            z-index: 100;
            border-top: 0.5px solid #c0c0c0
        }

        .layui-fluid {
            margin-bottom: 55px;
        }

        ::-webkit-scrollbar {
            display: none;
        }
    </style>
</head>
<body>
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body" style="padding-top: 40px;">
                <!-- 分布表单开始 -->
                <div class="layui-tab layui-steps layui-steps-readonly" lay-filter="formStepsStep"
                     style="max-width: 1000px;">
                    <!-- 标题 -->
                    <ul class="layui-tab-title">
                        <li class="layui-this">
                            <i class="layui-icon layui-icon-ok">1</i>
                            <span class="layui-steps-title">第一步</span>
                            <span class="layui-steps-content">基本配置</span>
                        </li>
                        <li>
                            <i class="layui-icon layui-icon-ok">2</i>
                            <span class="layui-steps-title">第二步</span>
                            <span class="layui-steps-content">列表页面</span>
                        </li>
                        <li>
                            <i class="layui-icon layui-icon-ok">3</i>
                            <span class="layui-steps-title">第三步</span>
                            <span class="layui-steps-content">表单页面</span>
                        </li>
                        <li>
                            <i class="layui-icon layui-icon-ok">4</i>
                            <span class="layui-steps-title">第四步</span>
                            <span class="layui-steps-content">代码预览</span>
                        </li>
                        <li>
                            <i class="layui-icon layui-icon-ok">5</i>
                            <span class="layui-steps-title">第五步</span>
                            <span class="layui-steps-content">生成完毕</span>
                        </li>
                    </ul>
                    <div class="layui-tab-content">

                        <div class="layui-tab-item layui-show">

                            <!-- 表单一 -->
                            <form id="form1" lay-filter="form1" class="layui-form" style="max-width: 1000px;margin: 0 auto;padding: 40px 30px 0 0;">

                                <div class="floot-btn">
                                    <div class="layui-btn-container text-right">
                                        <button class="layui-btn" lay-filter="formStepSubmit1" lay-submit>
                                            &emsp;下一步&emsp;
                                        </button>
                                    </div>
                                </div>
                                <hr />

                                <blockquote class="layui-elem-quote">文件名配置</blockquote>
                                <div class="layui-form-item form1-head">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">类名前缀</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="classPrefix" name="ClassPrefix" autocomplete="off"
                                                   class="layui-input" lay-verType="tips" lay-verify="required" oninput="ChangeClassName(this.value)">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">类名描述</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="classDescription" name="ClassDescription" autocomplete="off" class="layui-input"
                                                   lay-verType="tips" lay-verify="required">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">创建人员</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="createName" name="CreateName" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">实体类名</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="entityName" name="EntityName" data-suffix="Entity" autocomplete="off" class="layui-input layui-disabled" readonly>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">映射类名</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="entityMapName" name="EntityMapName" data-suffix="EntityMap" autocomplete="off" class="layui-input layui-disabled" readonly>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">创建日期</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="createDate" name="CreateDate" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">业务类名</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="businessName" name="BusinessName" data-suffix="BLL" autocomplete="off" class="layui-input layui-disabled" readonly>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">服务类名</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="serviceName" name="ServiceName" data-suffix="Service" autocomplete="off" class="layui-input layui-disabled" readonly>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">查询类名</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="entityParamName" name="EntityParamName" data-suffix="Param" autocomplete="off" class="layui-input layui-disabled" readonly>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">控制器名</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="controllerName" name="ControllerName" data-suffix="Controller" autocomplete="off" class="layui-input layui-disabled" readonly>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">列表页名</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="pageIndexName" name="PageIndexName" data-suffix="Index" autocomplete="off" class="layui-input layui-disabled" readonly>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-required">表单页名</label>
                                        <div class="layui-input-inline" style="width: 150px;">
                                            <input type="text" id="pageFormName" name="PageFormName" data-suffix="Form" autocomplete="off" class="layui-input layui-disabled" readonly>
                                        </div>
                                    </div>
                                </div>

                                <blockquote class="layui-elem-quote">其他配置</blockquote>
                                <div class="form1-foot">
                                    <div class="layui-row">
                                        <div class="layui-col-sm6">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label layui-form-required">实体继承</label>
                                                <div class="layui-input-block">
                                                    <select id="entityParent" name="EntityParent" lay-verType="tips" lay-verify="required">
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-col-sm6">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label layui-form-required">输出到所在模块</label>
                                                <div class="layui-input-block">
                                                    <select id="outputModule" name="OutputModule" lay-verType="tips" lay-verify="required">
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">输出目录</label>
                                        <div class="layui-input-block">
                                            <input type="text" id="outputEntity" name="OutputEntity" autocomplete="off" class="layui-input layui-disabled" readonly>
                                            <input type="hidden" id="outputWeb" name="OutputWeb" />
                                            <input type="hidden" id="outputBusiness" name="OutputBusiness" />
                                        </div>
                                    </div>
                                </div>
                            </form>

                        </div>

                        <div class="layui-tab-item">
                            <!-- 表单二 -->
                            <form class="layui-form" id="form2" lay-filter="form2" style="max-width: 1000px;margin: 0 auto;padding: 40px 30px 0 0;">

                                <div class="floot-btn">
                                    <div class="layui-btn-container text-right">
                                        <button type="button" class="layui-btn layui-btn-primary" data-steps="prev">
                                            上 一 步&nbsp;
                                        </button>
                                        <button class="layui-btn" lay-filter="formStepSubmit2" lay-submit>
                                            &emsp;下一步&emsp;
                                        </button>
                                    </div>
                                </div>
                                <hr />

                                <h3 class="layui-text">注意，Service中的查询条件默认被注释掉了，请自行调整。</h3>
                                <hr />

                                <blockquote class="layui-elem-quote">搜索编辑</blockquote>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">搜索栏:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="IsSearch" value="0" title="关闭">
                                        <input type="radio" name="IsSearch" value="1" title="启用" checked>
                                    </div>
                                </div>
                                <hr />
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">搜索字段:</label>
                                    <div class="layui-input-block" id="searchField">

                                    </div>
                                </div>
                                <blockquote class="layui-elem-quote">列表编辑</blockquote>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">列表字段:</label>
                                    <div class="layui-input-block" id="tableField">
                                    </div>
                                </div>
                                <blockquote class="layui-elem-quote">工具栏编辑</blockquote>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">新增按钮:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="AddStatus" value="0" title="关闭">
                                        <input type="radio" name="AddStatus" value="1" title="启用" checked>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">修改按钮:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="EditStatus" value="0" title="关闭">
                                        <input type="radio" name="EditStatus" value="1" title="启用" checked>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">删除按钮:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="DeleteStatus" value="0" title="关闭">
                                        <input type="radio" name="DeleteStatus" value="1" title="启用" checked>
                                    </div>
                                </div>
                            </form>
                        </div>

                        <div class="layui-tab-item">
                            <!-- 表单三 -->
                            <form class="layui-form" id="form3" lay-filter="form3" style="max-width: 1000px;margin: 0 auto;padding: 40px 30px 0 0;">

                                <div class="floot-btn">
                                    <div class="layui-btn-container text-right">
                                        <button type="button" class="layui-btn layui-btn-primary" data-steps="prev">
                                            上 一 步&nbsp;
                                        </button>
                                        <button class="layui-btn" lay-filter="formStepSubmit3" lay-submit>
                                            预览代码
                                        </button>
                                    </div>
                                </div>
                                <hr />

                                <blockquote class="layui-elem-quote">表单编辑</blockquote>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">表单字段:</label>
                                    <div class="layui-input-block" id="fromField">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">表单配置:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="ShowMode" value="1" title="单列" lay-filter="ShowMode" checked>
                                        <input type="radio" name="ShowMode" value="2" title="双列" lay-filter="ShowMode">
                                    </div>
                                </div>

                                <blockquote class="layui-elem-quote">表单预览</blockquote>
                                <div id="form-preview">
                                    <!-- 预览部分 -->
                                </div>
                                <hr />
                            </form>

                        </div>

                        <div class="layui-tab-item">
                            <!-- 表单四 -->
                            <form class="layui-form" id="form4" lay-filter="form4" style="max-width: 1000px;margin: 0 auto;padding: 40px 30px 0 0;">

                                <div class="floot-btn">
                                    <div class="layui-btn-container text-right">
                                        <button type="button" class="layui-btn layui-btn-primary" data-steps="prev">
                                            上 一 步&nbsp;
                                        </button>
                                        <button class="layui-btn" lay-filter="formStepSubmit4" lay-submit>
                                            生成代码
                                        </button>
                                    </div>
                                </div>
                                <hr />

                                <blockquote class="layui-elem-quote">可选参数</blockquote>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">页面代码:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="NeedHtml" value="0" title="关闭">
                                        <input type="radio" name="NeedHtml" value="1" title="生成" checked>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">控制器代码:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="NeedConroller" value="0" title="关闭">
                                        <input type="radio" name="NeedConroller" value="1" title="生成" checked>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label layui-form-required">侧边栏及权限:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="NeedSidebar" value="0" title="关闭">
                                        <input type="radio" name="NeedSidebar" value="1" title="创建" checked>
                                    </div>
                                </div>

                                <blockquote class="layui-elem-quote">代码预览</blockquote>
                                <div class="layui-tab layui-tab-card" lay-filter="docTabBrief">
                                    <ul class="layui-tab-title">
                                        <li>实体类</li>
                                        <li class="layui-this">实体查询类</li>
                                        <li>数据服务类</li>
                                        <li>数据服务接口</li>
                                        <li>业务类</li>
                                        <li>业务接口</li>
                                        <li>控制器</li>
                                        <li>列表页</li>
                                        <li>表单页</li>
                                    </ul>
                                    <div class="layui-tab-content">
                                        <div class="layui-tab-item">
                                            <pre class="layui-code" id="CodeEntity"></pre>
                                        </div>
                                        <div class="layui-tab-item layui-show">
                                            <pre class="layui-code" id="CodeEntityParam"></pre>
                                        </div>
                                        <div class="layui-tab-item">
                                            <pre class="layui-code" id="CodeService"></pre>
                                        </div>
                                        <div class="layui-tab-item">
                                            <pre class="layui-code" id="CodeIService"></pre>
                                        </div>
                                        <div class="layui-tab-item">
                                            <pre class="layui-code" id="CodeBusiness"></pre>
                                        </div>
                                        <div class="layui-tab-item">
                                            <pre class="layui-code" id="CodeIBusiness"></pre>
                                        </div>
                                        <div class="layui-tab-item">
                                            <pre class="layui-code" id="CodeController"></pre>
                                        </div>
                                        <div class="layui-tab-item">
                                            <pre class="layui-code" id="CodeIndex"></pre>
                                        </div>
                                        <div class="layui-tab-item">
                                            <pre class="layui-code" id="CodeForm"></pre>
                                        </div>

                                    </div>
                                </div>

                            </form>

                        </div>

                        <div class="layui-tab-item text-center" style="padding-top: 40px;">
                            <!-- 表单三 -->
                            <i class="layui-icon layui-icon-ok layui-circle"
                               style="background: #52C41A;color: #fff;font-size:30px;font-weight:bold;padding: 20px;line-height: 80px;"></i>
                            <div style="font-size: 24px;color: #333;margin-top: 30px;">操作成功</div>
                            <div style="font-size: 14px;color: #666;margin-top: 20px;">请查看项目</div>
                            <div style="text-align: center;margin: 50px 0 25px 0;">
                                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- //分布表单结束 -->

            </div>
        </div>
    </div>

    <!-- 页面模块选择 -->
    <script id="moduleListTpl" type="text/html" ew-tpl="moduleList">
        <div>
            {{# if(d){ }} <!-- 这里判断以下因为可能值还没定义 -->
            <form class="layui-form" action="" id="moduleListDiv" style="display:none;padding:20px;">
                <div class="layui-form-item">
                    {{# layui.each(d,function(i,item){ }}
                    <input type="radio" name="module" value="{{item}}" title="{{item}}" {{ (i == 0 ? 'checked':'') }}>
                    {{# }); }}
                </div>
                <hr />
                <div class="layui-form-item text-right" style="padding-top:10px;">
                    <button class="layui-btn" lay-filter="chooseModule" lay-submit>
                        确定
                    </button>
                </div>
            </form>
            {{# } }}
        </div>
    </script>

    <!-- 加载动画 -->
    <div class="page-loading">
        <div class="signal-loader">
            <span></span><span></span><span></span><span></span>
        </div>
    </div>

    <!-- js部分 -->
    <script src="/assets/libs/jquery/jquery-3.2.1.min.js"></script>
    <script src="/assets/libs/layui/layui.js"></script>
    <script src="/assets/js/utils.js"></script>
    <script src="/assets/js/main.js"></script>
    <script>
        var tableName = getRequestData("tableName");
        var chooseIndex;
        var module;

        layui.use(['layer', 'form', 'util', 'admin', 'setter', 'steps', 'formX', 'code'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var util = layui.util;
            var admin = layui.admin;
            var setter = layui.setter;
            var steps = layui.steps;
            var formX = layui.formX;

            util.fixbar();

            layui.code({
                encode: true //是否转义html标签。默认不开启
            });

            if (tableName) {

                // 选择生成模块
                admin.req('/ToolManage/CodeGenerator/GetModules', function (res) {

                    // 移除loading
                    admin.removeLoading();

                    if (res.Tag == 1) {

                        window.moduleList = res.Data;
                        admin.renderTpl('#moduleListTpl');
                        form.render('radio');

                        chooseIndex = admin.open({
                            type: 1,
                            title: '请选择对应模块',
                            closeBtn: 0,
                            content: $('#moduleListDiv'),
                            success: function (layero, index) {
                                form.on('submit(chooseModule)', function (data) {
                                    initPage(data.field.module);
                                    module = data.field.module;
                                    return false;
                                });
                            }
                        });


                    } else {
                        layer.msg(res.Message, { icon: 2, time: false });
                    }
                });



            } else {
                layer.msg("错误的访问！", { icon: 2, time: false });
            }

            var form1_data;
            /* 表单一提交事件 */
            form.on('submit(formStepSubmit1)', function (data) {
                form1_data = data.field;
                steps.next('formStepsStep');
                document.body.scrollTop = document.documentElement.scrollTop = 0;
                return false;
            });

            var form2_data;
            /* 表单二提交事件 */
            form.on('submit(formStepSubmit2)', function (data) {
                form2_data = data.field;
                steps.next('formStepsStep');
                document.body.scrollTop = document.documentElement.scrollTop = 0;
                return false;
            });

            var form3_data;
            var form3_result;
            var ButtonList;
            var TableField;
            var FromField;
            var SearchField;
            /* 表单三提交事件 */
            form.on('submit(formStepSubmit3)', function (data) {
                form3_data = data.field;
                // 将所有参数调整为后端需要的格式
                ButtonList = [];
                FromField = [];
                TableField = [];
                SearchField = [];

                if (form2_data.AddStatus == '1') {
                    ButtonList.push('btnAdd');
                }
                if (form2_data.EditStatus == '1') {
                    ButtonList.push('btnEdit');
                }
                if (form2_data.DeleteStatus == '1') {
                    ButtonList.push('btnDelete');
                }
                $('input[name=TableField]:checked').each(function () {
                    TableField.push($(this).val());
                });
                $('input[name=FromField]:checked').each(function () {
                    FromField.push($(this).val());
                });
                $('input[name=SearchField]:checked').each(function () {
                    SearchField.push($(this).val());
                });

                var allData = {
                    TableName: tableName,
                    EntityParent: form1_data.EntityParent,
                    FileConfig: {
                        ClassPrefix: form1_data.ClassPrefix,
                        ClassDescription: form1_data.ClassDescription,
                        CreateName: form1_data.CreateName,
                        EntityName: form1_data.EntityName,
                        EntityMapName: form1_data.EntityMapName,
                        CreateDate: form1_data.CreateDate,
                        BusinessName: form1_data.BusinessName,
                        ServiceName: form1_data.ServiceName,
                        EntityParamName: form1_data.EntityParamName,
                        ControllerName: form1_data.ControllerName,
                        PageIndexName: form1_data.PageIndexName,
                        PageFormName: form1_data.PageFormName
                    },
                    OutputConfig: {
                        OutputModule: form1_data.OutputModule,
                        OutputEntity: form1_data.OutputEntity,
                        OutputBusiness: form1_data.OutputBusiness,
                        OutputWeb: form1_data.OutputWeb
                    },
                    PageIndex: {
                        ButtonList: ButtonList,
                        ColumnList: TableField,
                        IsSearch: form2_data.IsSearch,
                        IsPagination: 1,
                        SearchField: SearchField
                    },
                    PageForm: {
                        ShowMode: form3_data.ShowMode,
                        FieldList: FromField
                    },
                    Module: module
                };

                admin.showLoading({
                    elem: 'body',
                    type: 3,
                    size: 'lg'
                });

                // 提交配置获取预览代码
                admin.req('/ToolManage/CodeGenerator/CodePreviewJson', allData, function (res) {
                    admin.removeLoading('body');
                    if (res.Tag == 1) {
                        $("#CodeEntityParam").html(res.Data.CodeEntityParam);
                        $("#CodeEntity").html(res.Data.CodeEntity);
                        $("#CodeService").html(res.Data.CodeService);
                        $("#CodeBusiness").html(res.Data.CodeBusiness);
                        $("#CodeIService").html(res.Data.CodeIService);
                        $("#CodeIBusiness").html(res.Data.CodeIBusiness);
                        $("#CodeController").html(res.Data.CodeController);
                        $("#CodeIndex").html(res.Data.CodeIndex);
                        $("#CodeForm").html(res.Data.CodeForm);
                        form3_result = res.Data;
                        steps.next('formStepsStep');
                    } else {
                        layer.msg(res.Message, { icon: 2, time: false });
                    }
                }, 'post');

                document.body.scrollTop = document.documentElement.scrollTop = 0;
                return false;
            });

            /* 表单四提交事件 */
            form.on('submit(formStepSubmit4)', function (data) {
                layer.confirm('即将生成代码，请确认以防误操作！', function (index) {

                    var postData = {
                        FileConfig: {
                            ClassPrefix: form1_data.ClassPrefix,
                            ClassDescription: form1_data.ClassDescription,
                            CreateName: form1_data.CreateName,
                            EntityName: form1_data.EntityName,
                            EntityMapName: form1_data.EntityMapName,
                            CreateDate: form1_data.CreateDate,
                            BusinessName: form1_data.BusinessName,
                            ServiceName: form1_data.ServiceName,
                            EntityParamName: form1_data.EntityParamName,
                            ControllerName: form1_data.ControllerName,
                            PageIndexName: form1_data.PageIndexName,
                            PageFormName: form1_data.PageFormName
                        },
                        OutputConfig: {
                            OutputModule: form1_data.OutputModule,
                            OutputEntity: form1_data.OutputEntity,
                            OutputBusiness: form1_data.OutputBusiness,
                            OutputWeb: form1_data.OutputWeb
                        },
                        TableName: tableName,
                        Code: encodeURIComponent(JSON.stringify(form3_result)),
                        NeedSidebar: data.field.NeedSidebar,
                        NeedConroller: data.field.NeedConroller,
                        NeedHtml: data.field.NeedHtml,
                        PageIndex: {
                            ButtonList: ButtonList,
                            ColumnList: TableField,
                            IsSearch: form2_data.IsSearch,
                            IsPagination: 1,
                            FieldList: FromField,
                            ShowMode: form3_data.ShowMode,
                            SearchField: SearchField
                        },
                        EntityParent: form1_data.EntityParent,
                        Module: module
                    };

                    admin.showLoading({
                        elem: 'body',
                        type: 3,
                        size: 'lg'
                    });

                    // 生成代码
                    admin.req('/ToolManage/CodeGenerator/CodeGenerateJson', postData, function (res) {
                        admin.removeLoading('body');
                        if (res.Tag == 1) {
                            steps.next('formStepsStep');
                        } else {
                            layer.msg(res.Message, { icon: 2, time: false });
                        }
                    }, 'post');

                    document.body.scrollTop = document.documentElement.scrollTop = 0;

                    layer.close(index);
                });

                return false;
            });

            // 监听表单预览的复选框
            form.on('checkbox(FromField)', function (data) {
                ChangeFormPreview();
            });

            // 监听表单预览的单选框
            form.on('radio(ShowMode)', function (data) {
                ChangeFormPreview();
            });

            /* 初始化 */
            function initPage(module) {
                admin.req('/ToolManage/CodeGenerator/GetBaseConfigJson', { tableName: tableName, module: module }, function (res) {

                    if (res.Tag == 1) {
                        // 表单数据
                        form.val('form1', res.Data.FileConfig);
                        form.val('form1', res.Data.OutputConfig);

                        var className = res.Data.ClassName;

                        ChangeClassName(className);
                        $('#classPrefix').val(className);

                        formX.renderSelect({
                            elem: '#outputModule',
                            data: res.Data.OutputConfig.ModuleList,
                            name: 'Key',
                            value: 'Value',
                            hint: '请选择',
                            done: function () { }
                        });
                        formX.renderSelect({
                            elem: '#entityParent',
                            data: res.Data.EntityParents,
                            name: '',
                            value: '',
                            hint: '请选择',
                            done: function () { }
                        });


                        layer.close(chooseIndex);
                    } else {
                        layer.msg(res.Message, { icon: 2, time: false });
                    }
                });
                /* 初始化表格字段 */
                admin.req('/ToolManage/CodeGenerator/GetTableFieldListJson', { tableName: tableName }, function (res) {
                    if (res.Tag == 1) {
                        setLayuiCheckbox(form, "tableField", 'TableField', res.Data, 'TableColumn', 'TableColumn');
                        setLayuiCheckbox(form, "searchField", 'SearchField', res.Data, 'TableColumn', 'TableColumn');
                        setLayuiCheckbox(form, "fromField", 'FromField', res.Data, 'TableColumn', 'TableColumn');
                    } else {
                        layer.msg(res.Message, { icon: 2, time: false });
                    }
                });
            }
        });

        // 批量修改固定名称
        function ChangeClassName(name) {

            var doms = $(".form1-head .layui-disabled");
            layui.each(doms, function (index, d) {
                var suffix = $(d).attr("data-suffix");
                $(d).val(name + suffix);
            })
        }

        // 表单预览
        function ChangeFormPreview() {
            // 所有勾选参数
            var arr_box = [];
            $('input[name=FromField]:checked').each(function () {
                arr_box.push($(this).val());
            });

            // 是否分两列
            var showMode = $("input[name=ShowMode]:checked").val();

            var h = [];
            for (var i = 0; i < arr_box.length; i++) {

                if (showMode == 2) {
                    h.push('<div class="layui-col-sm6">');
                } else {
                    h.push('<div class="layui-col-sm12">');
                }

                h.push('<div class="layui-form-item">');
                h.push('<label class="layui-form-label layui-form-required">' + arr_box[i] + '</label>');
                h.push('<div class="layui-input-block">');
                h.push('<input type="text" placeholder="请输入" class="layui-input" >');
                h.push('</div></div></div>');
            }

            $("#form-preview").html(h.join(''));
        }

    </script>
</body>
</html>